import {
  notice
} from '../../apis/group';
import {
  globalData
} from '../../utils/request';
const app = getApp();

Page({
  data: {
    titleTop: 0,
    titleHeight: 0,
    notice: {
      applyNum: 0,
      exchangeNum: 0,
      joinReplyNum: 0
    }
  },

  onLoad() {
    let menu = wx.getMenuButtonBoundingClientRect();
    this.setData({
      titleTop: menu.top + 2,
      titleHeight: menu.height,
      showGroupBtn: globalData.checkIn
    });
  },

  onShow() {
    this.getNotice();
  },

  getNotice() {
    notice().then(res => {
      if (res.data.code === 200) {
        let {
          data
        } = res.data, arr = new Array;
        for (let key in data) {
          arr.push(data[key]);
        };
        arr.some(v => v === 1) ? wx.showTabBarRedDot({
          index: 2
        }) : wx.hideTabBarRedDot({
          index: 2
        });
        this.setData({
          notice: res.data.data
        });
      };
    });
  },

  skip(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    });
  }
})